<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>小工匠订单管理系统</title>

    <link href="<%=path%>/resources/css/style.css" rel="stylesheet">
    <link href="<%=path%>/resources/css/style-responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="<%=path%>/resources/js/html5shiv.js"></script>
    <script src="<%=path%>/resources/js/respond.min.js"></script>
    <![endif]-->
</head>

<body class="sticky-header">

<section>
    <!-- left side start-->
    <%@ include file="/page/common/leftmenu.jsp" %>
    <!-- left side end-->

    <!-- main content start-->
    <div class="main-content" >

        <!-- header section start-->
        <%@ include file="/page/common/top.jsp" %>
        <!-- header section end-->

        <!-- page heading start-->
        <div class="page-heading">
            <h3>

            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">管理平台</a>
                </li>
                <li>维修业务管理</li>
                <li class="active">维修业务列表</li>
            </ul>
        </div>

        <!-- page heading end-->

        <!--body wrapper start-->
        <section class="wrapper">
            <!-- page start-->
            <div class="row">
                <div class="col-sm-12">
                    <div class="panel">

                        <header class="panel-heading">
                            条件筛选
                            <span class="tools pull-right">
                                <a href="<%=path%>/admin/bus/add_business.do"  data-toggle="modal" id="addBusiness" class="btn">新增</a>
                                <a href="javascript:void(0)"  data-toggle="modal" id="editBusiness"  id="编辑" class="btn">编辑</a>
                                <a href="#" id="delBusiness" class="btn">删除</a>
                             </span>
                        </header>
                        <div class="panel-body toolbar">
                            <div class="row">
                                <div class="col-md-1" style="width:120px">
                                    <label> 单项工程：</label>
                                </div>
                                <div class="col-md-2">
                                    <select id="two_type_select" class="form-control selectpicker" data-live-search="true">
                                        <option value="-1">全部</option>
                                    </select>
                                </div>
                            </div>
                            <p>&nbsp;</p>
                            <div class="row">
                                <div class="col-md-1" style="margin-top: 5px;width:130px">
                                    <label>分项工程名称：</label>
                                </div>
                                <div class="col-md-2 input-group" style="margin-left: 20px">
                                    <input id="searchKey" class="form-control" type="text" placeholder="请输入关键词">
                                    <span class="input-group-btn">
                                        <button type="button"  onclick="search()" class="btn btn-primary">查询</button>
                                        </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="table table-striped table-hover table-bordered" id="editable-sample">
                <div class="table-responsive" data-pattern="priority-columns" data-focus-btn-icon="fa-asterisk"
                     data-sticky-table-header="true" data-add-display-all-btn="true" data-add-focus-btn="true">
                    <table id="table" data-unique-id="id"
                           data-pagination="true"
                           data-id-field="id"
                           data-maintain-selected="true"
                           data-page-size="10"
                           data-page-list="[5,10,15,20]"
                           data-side-pagination="server">
                    </table>
                </div>
            </div>

            <!-- Modal -->
            <!-- modal -->
            <!-- page end-->
        </section>


        <!--body wrapper end-->

        <!--footer section start-->
        <%@ include file="/page/common/footer.jsp" %>
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>

<!-- Placed js at the end of the document so the pages load faster -->
<script src="<%=path%>/resources/js/jquery-1.10.2.min.js"></script>
<script src="<%=path%>/resources/js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="<%=path%>/resources/js/jquery-migrate-1.2.1.min.js"></script>
<script src="<%=path%>/resources/js/bootstrap.min.js"></script>
<script src="<%=path%>/resources/js/bootstrap.min.js"></script>
<script src="<%=path%>/resources/js/bootstrap-table.js"></script>

<script src="<%=path%>/resources/js/modernizr.min.js"></script>
<script src="<%=path%>/resources/js/jquery.nicescroll.js"></script>
<script src="<%=path%>/resources/js/jquery-confirm.js"></script>
<!--common scripts for all pages-->
<script src="<%=path%>/resources/js/scripts.js"></script>
<script src="<%=path%>/resources/js/jquery.isotope.js"></script>

<script src="<%=path%>/resources/js/common.js"></script>
<script>
    var offset = -1;
    var $table = $('#table'), selections = [];
    $(function () {
        init_two_type();
        initData();
    });
    function init_two_type() {
        $.ajax({
            url: '<%=basePath %>/admin/btype/get_two_type.do?&pid=1',
            async: false,
            success: function (data) {
                $.each(data.data, function (idx, obj) {
                    var value = obj.bId;
                    $('#two_type_select').append('<option value=' + value + '>' + obj.bName + '</option>')
                });
            }
        });
    }

    /*初始化表格数据*/
    function initData() {
        $('#table').bootstrapTable({
            url: "<%=path %>/admin/bus/business_select.do",
            clickToSelect: 'true',//选中一行
            queryParams: queryParams,
            columns: [{
                field: 'checked',
                checkbox: true
            }, {
                field: 'ID',
                title: '编号',
                width: '150'
            }, {
                field: 'B_TYPE_NAME',
                title: '单位工程',
                width: '150'
            }, {
                field: 'B_NAME',
                title: '分项工程',
                width: '150'
            }, {
                field: 'PRICE',
                title: '价格(元)',
                width: '150'
            }, {
                field: 'LOGO',
                title: '工程缩放图',
                formatter: 'logoFormatter'
            }]
        });
    }

    /*刷新*/
    function search() {
        offset = 0;
        $table.bootstrapTable('refresh');
    }

    /**封装查询条件**/
    function queryParams(params) {
        if (offset == 0) {
            params.offset = offset;
        }
        offset = -1;
        var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            limit: params.limit,  //页面大小
            offset: params.offset, //页码
            pid: $("#two_type_select").val(),
            searchKey: $("#searchKey").val(),
            maxrows: params.limit,
            pageindex: params.pageNumber
        };
        return temp;
    }


    $('#delBusiness').on('click',function(){
        var ids = getIdSelections();
        var num = $table.bootstrapTable('getSelections').length;
        if(ids.length==0){
            alert("至少选择一条正确的记录");
        }else{
            if(confirm("确定要删除吗？")){
                delBusiness(ids);
            }
        }
    });
    function delBusiness(ids){
        $.ajax({
            type: "GET",
            url: "<%= basePath %>/admin/bus/delBusiness.do",
            dataType:'json',
            data: { ids : ids.toString()},
            success: function(data){
                if(data.code=='200'){
                    alert("删除成功");
                    window.location.reload();//刷新当前页面.

                }else{
                    alert("删除失败");
                    window.location.reload();//刷新当前页面.
                }
            }
        });
    }

    function getIdSelections() {
        return $.map($table.bootstrapTable('getSelections'), function (row) {
            return row.ID;
        })
    }

        $(function() {
            var $container = $('#gallery');
            $container.isotope({
                itemSelector: '.item',
                animationOptions: {
                    duration: 750,
                    easing: 'linear',
                    queue: false
                }
            });

            // filter items when filter link is clicked
            $('#filters a').click(function() {
                var selector = $(this).attr('data-filter');
                $container.isotope({filter: selector});
                return false;
            });
        });

    $('#editBusiness').on('click',function(){
        var id = getIdSelections();
        if(id.length==0){
            alert("请选择需要修改的分项工程名称");
        }else if(id.length==1){
            window.location.href="/admin/bus/edit_business.do?id="+id;
        }else{
            alert("只能选择一条分项工程的名称进行编辑");
        }
    });

    function logoFormatter(value){
        var context="<img width='100px' height='30px' src='<%=path%>/upload/bus/"+value+"'>"
       return context;
    }
    jQuery(document).ready(function($)
    {
        selectEffect("admin/bus/business_list.do");
    });
</script>
</body>
</html>

